package com.example.swagger2.test;/*
   
/**
* @program: demo
*
* @description: swagger2的配置类
*
* @author: kk
*
* @create: 2020-02-05 10:39
**/

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
//@Configuration表明该类是一个配置类
//@EnableSwagger2启用Swagger2
//swagger的接口管理页面http://localhost:8080/swagger-ui.html
@Configuration
@EnableSwagger2
public class Swagger2 {
    @Bean
    public Docket createRestApi(){
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.example.swagger2.test.demo"))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo(){
        return new ApiInfoBuilder()
                .title("Spring boot 使用swagger2构建RESTful apis")
                .description("文档样例")
                .termsOfServiceUrl("http://localhost:8080/swagger-ui.html")
                .contact("by kk")
                .version("1.O")
                .build();
    }
}
